package org.platform.lwc.redis.factory.lettuce;

import cn.hutool.core.util.ObjectUtil;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;

/**
 * @Description: 根据RedisProperties 获取 LettuceConnectionFactory 工厂
 * @Author: lwc
 * @Date: 2021/5/20
 */
public class ObtainLettuceConnectionFactory {

   public LettuceConnectionFactory getObtainLettuceConnection(RedisProperties redisProperties) {

        if (ObjectUtil.isNotNull(redisProperties.getSentinel())) {//从spring.redis.password.sentinel.password 配置获取密码
            return new SentinelObtainLettuceConnection().obtainLettuceConnection(redisProperties);
        } else if (ObjectUtil.isNotNull(redisProperties.getCluster())) {//从spring.redis.password 配置获取密码
            return new ClusterObtainLettuceConnection().obtainLettuceConnection(redisProperties);
        } else {
            return new StandAloneObtainLettuceConnection().obtainLettuceConnection(redisProperties);
        }
    }
}
